﻿/*
作者:walkman
邮箱:winstepscn@163.com
QQ:27800640


[用途]:
改善asp.net的验证控件的显示效果，用比较人性化的气泡提示来替换掉原来枯燥的界面提示,并带有"关闭提示"的功能.

[注意]:
本程序在.net2.0下，IE6、Firefox2下通过，但不保证能适应所有浏览器。

[版权相关]:
欢迎大家使用和转载本程序，但是为了尊重作者的劳动成果，请转载时不要将作者的联系信息去掉；也欢迎大家根据这个思路创造出更好的验证提示效果，同时也请将修改后的程序发一份给作者本人，欢迎交流，共同进步。此气泡特效参考了蓝色理想中的代码，在此表示感谢。


[演示和下载]:
http://www.shouji138.com/aspnet2/
*/

if(typeof(__Win__IsAutoClose)=="undefined" || typeof(__Win__IsFilterClose)=="undefined" || typeof(__Win__CloseWaitTime)=="undefined")
{
    alert("初始化Js失败，请确定正确使用了气泡提示验证控件！")
}
var __Win__BlockFlag = false;


 
//关闭气泡提示
function HideWinErrMsgTips(elementid)
{

    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    
    var objWinDiv = document.getElementById(elementid);

    if(isIE&&typeof(__Win__IsFilterClose)!="undefined"&&__Win__IsFilterClose)
    {
       __Win__BlockFlag = false;
       HideIEWinErrMsgTips(objWinDiv.id);
    }
    else
    {
	    objWinDiv.style.visibility = "hidden";
	}
}

function HideIEWinErrMsgTips(elementid)
{
     var obj___ = document.getElementById(elementid+"____")
     var  opacty=obj___.filters.alpha.opacity;   
     obj___.filters.alpha.opacity-=9;
     if(obj___.filters.alpha.opacity>0)
     {
        if(!__Win__BlockFlag)
            setTimeout("HideIEWinErrMsgTips('"+elementid+"')",100);
     }
     else
     {
        document.getElementById(elementid).style.visibility = "hidden";
     }
    
}

//得到某obj的x,y坐标,兼容大部分的浏览器
function getWinElementPos(obj)
{

 var ua = navigator.userAgent.toLowerCase();
 var isOpera = (ua.indexOf('opera') != -1);
 var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof

 var el = obj;

 if(el.parentNode === null || el.style.display == 'none') 
 {
  return false;
 }

 var parent = null;
 var pos = [];
 var box;

 if(el.getBoundingClientRect) //IE
 {
  box = el.getBoundingClientRect();
  var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);

  return {x:box.left + scrollLeft, y:box.top + scrollTop};
 }
 else if(document.getBoxObjectFor) // gecko
 {
  box = document.getBoxObjectFor(el);
     
  var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
  var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;

  pos = [box.x - borderLeft, box.y - borderTop];
 }
 else // safari & opera
 {
  pos = [el.offsetLeft, el.offsetTop];
  parent = el.offsetParent;
  if (parent != el) {
   while (parent) {
    pos[0] += parent.offsetLeft;
    pos[1] += parent.offsetTop;
    parent = parent.offsetParent;
   }
  }
  if (ua.indexOf('opera') != -1 
   || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) 
  {
    pos[0] -= document.body.offsetLeft;
    pos[1] -= document.body.offsetTop;
  } 
 }
  
 if (el.parentNode) { parent = el.parentNode; }
 else { parent = null; }
  
 while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
 { // account for any scrolled ancestors
  pos[0] -= parent.scrollLeft;
  pos[1] -= parent.scrollTop;
  
  if (parent.parentNode) { parent = parent.parentNode; } 
  else { parent = null; }
 }
 return {x:pos[0], y:pos[1]};
}

